<template>
  <div class="app-container">
    <el-form
      ref="listFilterRef"
      :model="list.filter"
      inline
      class="list-filter"
    >
      <el-form-item prop="type">
        <KiSelect
          v-model="list.filter.type"
          :options="dict.link_type"
          placeholder="类型"
        />
      </el-form-item>
      <el-form-item prop="status">
        <Status v-model="list.filter.status" />
      </el-form-item>
      <el-form-item prop="effect">
        <KiSelect
          v-model="list.filter.effect"
          :options="[
            { dataValue: true, dataName: '生效中' },
            { dataValue: false, dataName: '未生效' }
          ]"
          placeholder="是否生效"
        />
      </el-form-item>
      <el-form-item>
        <el-button @click="reset">
          重置
        </el-button>
      </el-form-item>
    </el-form>

    <div class="table-operation">
      <AuthButton @click="c" name="新增" />
      <el-pagination
        v-bind="elPaginationProps"
        :total="list.total"
        :currentPage.sync="list.filter.pageNo"
        :pageSize.sync="list.filter.pageSize"
      />
    </div>

    <el-table v-loading="list.loading" :data="list.data" v-bind="tableProp">
      <el-table-column label="展示顺序" prop="sort" />
      <el-table-column label="名称" prop="name" />
      <el-table-column label="跳转类型">
        <template slot-scope="{ row }">
          {{ row.type | $value2label(dict.link_type) }}
        </template>
      </el-table-column>
      <el-table-column label="生效时间" prop="startTime" />
      <el-table-column label="结束时间" prop="endTime">
        <template slot-scope="{ row }">
          {{ row.endTime }}
          <Expired :endTime="row.endTime" />
        </template>
      </el-table-column>
      <el-table-column label="启用状态" width="80" align="center">
        <template slot-scope="{ row: { id, status } }">
          <KiPopSwitch
            v-bind="popSwitchProps(status)"
            @change="updateStatus({ id, status: status ^ 1 })"
          />
        </template>
      </el-table-column>
      <el-table-column label="操作" class-name="small-padding">
        <template slot-scope="{ row }">
          <auth-button @click="u({ id: row.id })" name="编辑" />
          <auth-button @click="d({ id: row.id })" name="删除" />
        </template>
      </el-table-column>
    </el-table>

    <KiFormDialog
      :show.sync="form.show"
      :title="formTitle"
      v-model="form.data"
      :submit="submitForm"
      :readonly="form.status === 'r'"
      ref="formRef"
      :loading="form.loading"
    >
      <template #el-form>
        <el-form-item label="置顶内容" prop="sourceId" verify>
          <GlobalSearch
            v-if="form.show"
            v-model="form.data.sourceId"
            :type.sync="form.data.type"
            :sourceId.sync="form.data.sourceId"
            :sourceName.sync="form.data.name"
          />
        </el-form-item>
        <el-form-item label="生效时间" prop="startTime" verify>
          <TimeRangePicker
            :start.sync="form.data.startTime"
            :end.sync="form.data.endTime"
            placeholder="生效起期/生效止期"
          />
        </el-form-item>
        <el-form-item label="序号" prop="sort" verify>
          <Sort v-model="form.data.sort" />
        </el-form-item>
      </template>
    </KiFormDialog>
  </div>
</template>

<script>
import pageMixin from '@/utils/pageMixin'
import useAdmateAdapter from '@/utils/useAdmateAdapter'
import Expired from '@/components/Expired'

export default {
  mixins: [pageMixin],
  components: { Expired },
  setup: () =>
    useAdmateAdapter({
      urlPrefix: 'one-travel-api/discover-top'
    })
}
</script>

<style lang="scss" scoped></style>
